package com.loveofsoftware.quotes;

import com.loveofsoftware.quotes.R;

import android.app.Activity;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

public class ImagePageActivity extends Activity {

	final int totalImages = 18;
	int currIndex = 0;
	ImageView imageView;

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		outState.putInt("CURRINDEX", currIndex);		
	}
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
        
        imageView = new ImageView(this);
        setContentView(imageView);
        
        if (null != savedInstanceState
				&& 0 != savedInstanceState.getInt("TOKEN")) {
			currIndex = savedInstanceState.getInt("CURRINDEX");			
		}
		
		setText();
	
    }
    
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {        	
            currIndex =(currIndex+1)%totalImages;
            setText();
        }
        return true;
    }

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.navigation_menu, menu);
		return true;

	}
	
	private void setText()
	{
		Animation myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fadein);
		  
		  
		  myFadeInAnimation.setDuration(10000);
		imageView.setAnimation(myFadeInAnimation);
		switch(currIndex)
		{
		case 0:
			imageView.setImageResource(R.drawable.ramana);
			break;
		case 1:
			imageView.setImageResource(R.drawable.sri_sri_ravishankar);
			break;
		case 2:
			imageView.setImageResource(R.drawable.shri_nisargadatta_maharaj);
			break;
		case 3:
			imageView.setImageResource(R.drawable.jesus);
			break;
		case 4:
			imageView.setImageResource(R.drawable.sri_krishna);
			break;
		case 5:
			imageView.setImageResource(R.drawable.wahihudin);
			break;
		case 6:
			imageView.setImageResource(R.drawable.vivekananda);
			break;
		case 7:
			imageView.setImageResource(R.drawable.ramadan);
			break;
		case 8:
			imageView.setImageResource(R.drawable.adishankaracharya);
			break;
		case 9:
			imageView.setImageResource(R.drawable.guru_nanak_dev_ji);
			break;
		case 10:
			imageView.setImageResource(R.drawable.buddha);
			break;
		case 11:
			imageView.setImageResource(R.drawable.lao_tzu);
			break;	
		case 12:
			imageView.setImageResource(R.drawable.osho);
			break;
		case 13:
			imageView.setImageResource(R.drawable.yogananda);
			break;
		case 14:
			imageView.setImageResource(R.drawable.ramakrishna_paramhansa);
			break;
		case 15:
			imageView.setImageResource(R.drawable.krishnamurti);
			break;
		case 16:
			imageView.setImageResource(R.drawable.dalai_lama);
			break;
		case 17:
			imageView.setImageResource(R.drawable.rb_ramesh);
			break;
		}
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.next:
			 currIndex =(currIndex+1)%totalImages;
			 setText();
			return true;
		case R.id.prev:
			if(0 == currIndex)
				currIndex = totalImages -1;
			else
				currIndex --;
			setText();
			return true;
		case R.id.exit:
			this.finish();
			return true;
		default:
			return super.onContextItemSelected(item);
		}
	}
}